package com.zhou.jianzhi.controller.web;/**
 * @project jianzhi-server-master
 * @description
 * @author 黄嘉杰
 * @date 2025/1/21 15:34:22
 * @version 1.0
 */

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.zhou.jianzhi.common.AjaxResult;
import com.zhou.jianzhi.entity.dto.HrInfoDTO;
import com.zhou.jianzhi.entity.dto.HrInfoDTOC;
import com.zhou.jianzhi.entity.po.HrInfo;
import com.zhou.jianzhi.entity.po.SysImage;
import com.zhou.jianzhi.mapper.SysImageMapper;
import com.zhou.jianzhi.service.IHrInfoService;
import com.zhou.jianzhi.service.SysImageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @description: TODO
 * @author 黄嘉杰
 * @date 2025/1/21 15:34
 * @version 1.0
 */
@RestController
@RequestMapping("/imageInfo")
public class ImageController {


    @Autowired
    private SysImageService imageService;

    @Autowired
    private SysImageMapper mapper;
    /**
     * 根据id修改hr_info
     */
    @PostMapping("/edit")
    public AjaxResult edit(@RequestBody SysImage sysImage) {
        QueryWrapper<SysImage> id1 = new QueryWrapper<>();
        if (sysImage.getId()!=null){
            id1.eq("id",sysImage.getId());
        }
        if (sysImage.getRelatedId()!=null){
            id1.eq("related_id",sysImage.getRelatedId());
        }
        if (sysImage.getRelatedType()!=null){
            id1.eq("related_type",sysImage.getRelatedType());
        }
        if (sysImage.getJobSeekerId()!=null){
            id1.eq("job_seeker_id",sysImage.getJobSeekerId());
        }
        if (sysImage.getRecruitUnitId()!=null){
            id1.eq("recruit_unit_id",sysImage.getRecruitUnitId());
        }
        SysImage sysImage1 = mapper.selectOne(id1);
        sysImage1.setUrl(sysImage.getUrl());

        return AjaxResult.success(imageService.saveOrUpdate(sysImage1));
    }

    /**
     * 根据hr_info表id查询hr_info
     */
    @GetMapping("/getById")
    public AjaxResult selectById(@RequestParam Long id) {
        QueryWrapper<SysImage> id1 = new QueryWrapper<>();
        id1.eq("id",id);
        SysImage hrInfo = imageService.getOne(id1);
        if (hrInfo==null){
            return AjaxResult.error("查不到");
        }
        return AjaxResult.success(hrInfo);
    }


    /**
     * 根据条件查询返回一条hr_info
     */
    @PostMapping("/getOne")
    public AjaxResult selectOne(@RequestBody SysImage sysImage) {
        QueryWrapper<SysImage> id1 = new QueryWrapper<>();
        if (sysImage.getId()!=null){
            id1.eq("id",sysImage.getId());
        }
        if (sysImage.getRelatedId()!=null){
            id1.eq("related_id",sysImage.getRelatedId());
        }
        if (sysImage.getRelatedType()!=null){
            id1.eq("related_type",sysImage.getRelatedType());
        }
        if (sysImage.getJobSeekerId()!=null){
            id1.eq("job_seeker_id",sysImage.getJobSeekerId());
        }
        if (sysImage.getRecruitUnitId()!=null){
            id1.eq("recruit_unit_id",sysImage.getRecruitUnitId());
        }
        SysImage sysImage1 = mapper.selectOne(id1);
        if (sysImage1==null){
            return AjaxResult.error("查不到");
        }
        return AjaxResult.success(sysImage1);
    }



    /**
     * 查询hr_info列表
     */
    @PostMapping("/list")
    public AjaxResult list(@RequestBody SysImage sysImage) throws Exception{
        QueryWrapper<SysImage> id1 = new QueryWrapper<>();
        if (sysImage.getId()!=null){
            id1.eq("id",sysImage.getId());
        }
        if (sysImage.getRelatedId()!=null){
            id1.eq("related_id",sysImage.getRelatedId());
        }
        if (sysImage.getRelatedType()!=null){
            id1.eq("related_type",sysImage.getRelatedType());
        }
        if (sysImage.getJobSeekerId()!=null){
            id1.eq("job_seeker_id",sysImage.getJobSeekerId());
        }
        if (sysImage.getRecruitUnitId()!=null){
            id1.eq("recruit_unit_id",sysImage.getRecruitUnitId());
        }
        List<SysImage> sysImages = mapper.selectList(id1);
        return sysImages.size()>0?AjaxResult.success(sysImages):AjaxResult.error("查不到");
    }







}
